package com.mcc.web.controller.monitor;

import java.util.List;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.mcc.common.annotation.Log;
import com.mcc.common.core.controller.BaseController;
import com.mcc.common.core.domain.AjaxResult;
import com.mcc.common.core.page.TableDataInfo;
import com.mcc.common.enums.BusinessType;
import com.mcc.system.domain.SysOperLog;
import com.mcc.system.service.ISysOperLogService;

/**
 * 操作日志记录
 *
 * @author gxy
 */
@Api(tags = "操作日志")
@ApiSort(5)
@RestController
@RequestMapping("/monitor/operlog")
public class SysOperlogController extends BaseController {

    @Autowired
    private ISysOperLogService operLogService;

    @ApiOperation("获取操作日志列表")
    @ApiOperationSupport(order = 1)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
    @GetMapping("/list")
    public AjaxResult<TableDataInfo<SysOperLog>> list(SysOperLog operLog) {
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        return getDataTable(list);
    }

    @ApiOperation("获取操作日志列表(分页)")
    @ApiOperationSupport(order = 2)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
    @GetMapping("/page")
    public AjaxResult<TableDataInfo<SysOperLog>> page(SysOperLog operLog) {
        startPage();
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        return getDataTable(list);
    }

    @ApiOperation("删除操作日志")
    @ApiOperationSupport(order = 3)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @PostMapping("/remove/{operIds}")
    public AjaxResult remove(@PathVariable Long[] operIds) {
        return toAjax(operLogService.deleteOperLogByIds(operIds));
    }

    @ApiOperation("清空操作日志")
    @ApiOperationSupport(order = 4)
    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @PostMapping("/clean")
    public AjaxResult clean() {
        operLogService.cleanOperLog();
        return AjaxResult.success();
    }
}
